home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
xlisp_21.zoo
/
xl-xs001.bug
< prev
next >
Wrap
Internet Message Format
|
1990-02-28
|
3KB
From sce!mitel!uunet!mcvax!kth!draken!liuida!mikpe Fri Apr 14 14:35:35 EDT 1989
Article: 85 of comp.lang.lisp.x
Path: cognos!sce!mitel!uunet!mcvax!kth!draken!liuida!mikpe
From: mikpe@senilix.ida.liu.se (Mikael Pettersson)
Newsgroups: comp.lang.lisp.x
Subject: X{scheme,lisp} bugs
Summary: operating on closed files can cause NULL dereferences
Message-ID: <1244@senilix.ida.liu.se>
Date: 13 Apr 89 04:13:07 GMT
Organization: CIS Dept, Univ of Linkoping, Sweden
Lines: 61
I stumbled across a bug in Xscheme's handling of ports. It turns out
that none of the functions that take ports as arguments check whether
the port is open (i.e. it hasn't been closed) (except xclose() itself!).
Sending a closed port to e.g. READ causes a NULL dereference down in
the OS specific stuff: on my UNIX machine Xscheme dies with a SIGSEGV.
The easiest fix (although it has the side-effect of making PORT? return #F
for closed ports) is to change the portp() macro in xscheme.h like this:
*** xscheme.h.~1~ Sun Feb 19 13:25:29 1989
--- xscheme.h Wed Apr 12 18:41:26 1989
***************
*** 207,213 ****
#define consp(x) ((x) && ntype(x) == CONS)
#define stringp(x) ((x) && ntype(x) == STRING)
#define symbolp(x) ((x) && ntype(x) == SYMBOL)
! #define portp(x) ((x) && ntype(x) == PORT)
#define objectp(x) ((x) && ntype(x) == OBJECT)
#define fixp(x) ((x) && ntype(x) == FIXNUM)
#define floatp(x) ((x) && ntype(x) == FLONUM)
--- 207,213 ----
#define consp(x) ((x) && ntype(x) == CONS)
#define stringp(x) ((x) && ntype(x) == STRING)
#define symbolp(x) ((x) && ntype(x) == SYMBOL)
! #define portp(x) ((x) && ntype(x) == PORT && getfile(x))
#define objectp(x) ((x) && ntype(x) == OBJECT)
#define fixp(x) ((x) && ntype(x) == FIXNUM)
#define floatp(x) ((x) && ntype(x) == FLONUM)
I then went to see if Xlisp was equally fragile, but luckily it wasn't.
Only xformat() (due to it's checking for NIL, T and unnamed streams)
misses to check that the file is open.
The following patch fixes that problem (your line numbers may vary):
*** xlfio.c.~1~ Mon Dec 19 06:07:30 1988
--- xlfio.c Wed Apr 12 20:35:40 1989
***************
*** 410,416 ****
else {
if (stream == true)
stream = getvalue(s_stdout);
! else if (!streamp(stream) && !ustreamp(stream))
xlbadtype(stream);
val = NIL;
}
--- 410,420 ----
else {
if (stream == true)
stream = getvalue(s_stdout);
! else if (streamp(stream)) { /* copied from xlgetfile() */
! if (getfile(stream) == NULL)
! xlfail("file not open");
! }
! else if (!ustreamp(stream))
xlbadtype(stream);
val = NIL;
}
--
Mikael Pettersson, Dept of Comp & Info Sci, University of Linkoping, Sweden
email: mpe@ida.liu.se or ..!{mcvax,munnari,uunet}!enea!liuida!mpe